notebook: Add api to complete tab dnd from the outside
authorMatthias Clasen <mclasen@redhat.com>
Thu, 12 Feb 2015 22:33:10 +0000 (17:33 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 12 Feb 2015 22:33:10 +0000 (17:33 -0500)
This is necessary to avoid unwanted drag cancel animations,
now that GtkNotebook is careful about cancelling a drag
when the dragged tab disappears unexpectedly.

docs/reference/gtk/gtk3-sections.txt
gtk/gtknotebook.c

index 88f20c383594ba16fd73e24448221592c3524bbe..7db2ee399d0e4a462267ff70599e3adf43448dc8 100644 (file)
@@ -2485,6 +2485,7 @@ gtk_notebook_prepend_page_menu
 gtk_notebook_insert_page
 gtk_notebook_insert_page_menu
 gtk_notebook_remove_page
+gtk_notebook_detach_tab
 gtk_notebook_page_num
 gtk_notebook_next_page
 gtk_notebook_prev_page
index 3953eececf01e2e1501f154a847451d789c855d7..3de4692cc15227863c2dcbd904224dfa9d155cd0 100644 (file)
@@ -3925,6 +3925,29 @@ gtk_notebook_drag_drop (GtkWidget        *widget,
   return FALSE;
 }
 
+/**
+ * gtk_notebook_detach_tab:
+ * @notebook: a #GtkNotebook
+ * @child: a child
+ *
+ * Removes the child from the notebook.
+ *
+ * This function is very similar to gtk_container_remove(),
+ * but additionally informs the notebook that the removal
+ * is happening as part of a tab DND operation, which should
+ * not be cancelled.
+ *
+ * Since: 3.16
+ */
+void
+gtk_notebook_detach_tab (GtkNotebook *notebook,
+                         GtkWidget   *child)
+{
+  notebook->priv->remove_in_detach = TRUE;
+  gtk_container_remove (GTK_CONTAINER (notebook), child);
+  notebook->priv->remove_in_detach = FALSE;
+}
+
 static void
 do_detach_tab (GtkNotebook     *from,
                GtkNotebook     *to,
@@ -3959,9 +3982,7 @@ do_detach_tab (GtkNotebook     *from,
                            "detachable", &detachable,
                            NULL);
 
-  from->priv->remove_in_detach = TRUE;
-  gtk_container_remove (GTK_CONTAINER (from), child);
-  from->priv->remove_in_detach = FALSE;
+  gtk_notebook_detach_tab (from, child);
 
   gtk_widget_get_allocation (GTK_WIDGET (to), &to_allocation);
   to_priv->mouse_x = x + to_allocation.x;
@@ -8406,6 +8427,14 @@ gtk_notebook_get_tab_detachable (GtkNotebook *notebook,
  * destination and accept the target “GTK_NOTEBOOK_TAB”. The notebook
  * will fill the selection with a GtkWidget** pointing to the child
  * widget that corresponds to the dropped tab.
+ *
+ * Note that you should use gtk_notebook_detach_tab() instead
+ * of gtk_container_remove() if you want to remove the tab from
+ * the source notebook as part of accepting a drop. Otherwise,
+ * the source notebook will think that the dragged tab was
+ * removed from underneath the ongoing drag operation, and
+ * will initiate a drag cancel animation.
+ *
  * |[<!-- language="C" -->
  *  static void
  *  on_drag_data_received (GtkWidget        *widget,
@@ -8419,14 +8448,12 @@ gtk_notebook_get_tab_detachable (GtkNotebook *notebook,
  *  {
  *    GtkWidget *notebook;
  *    GtkWidget **child;
- *    GtkContainer *container;
  *
  *    notebook = gtk_drag_get_source_widget (context);
  *    child = (void*) gtk_selection_data_get_data (data);
  *
  *    process_widget (*child);
- *    container = GTK_CONTAINER (notebook);
- *    gtk_container_remove (container, *child);
+ *    gtk_notebook_detach_tab (GTK_NOTEBOOK (notebook), *child);
  *  }
  * ]|
  *